import { Module, OnModuleInit } from '@nestjs/common';
import { TypeOrmModule, TypeOrmModuleOptions } from '@nestjs/typeorm';
import { Logger } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { databaseConfig } from './config/database.config';
import { ArticlesModule } from './modules/articles/articles.module';
import { Connection } from 'typeorm';
@Module({
  imports: [
    TypeOrmModule.forRoot(databaseConfig as TypeOrmModuleOptions),
    ArticlesModule,
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule implements OnModuleInit {
  private readonly logger = new Logger(AppModule.name);

  constructor(private connection: Connection) {}

  onModuleInit() {
    if (this.connection.isConnected) {
      this.logger.log('数据库连接成功！');
    } else {
      this.logger.error('数据库连接失败！');
    }
  }
}
